package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.ProcessCompound;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.ProcessCompoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("processCompound")
public class ProcessCompoundController {

    @Autowired
    private ProcessCompoundService processCompoundService;

    @GetMapping("{id}")
    public Result findById(@PathVariable long id){

        return processCompoundService.findById(id);

    }

    @GetMapping("{type}/{page}/{size}")
    public Result findAllByType(@PathVariable String type,@PathVariable int page,@PathVariable int size){

        return processCompoundService.findAllByType(type, page, size);

    }

    @GetMapping("{type}/{state}/{page}/{size}")
    public Result findAllByTypeAndState(@PathVariable String type,@PathVariable String state,@PathVariable int page,@PathVariable int size){

        return processCompoundService.findAllByTypeAndState(type, state, page, size);

    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id){

        return processCompoundService.deleteById(id);

    }

    @PostMapping
    public Result save(@RequestBody ProcessCompound processCompound){

        return processCompoundService.save(processCompound);

    }

    @PutMapping("{id}")
    public Result update(@RequestBody ProcessCompound processCompound,@PathVariable Long id){

        return processCompoundService.update(processCompound,id);

    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap,@PathVariable int page, @PathVariable int size){

        return processCompoundService.Search(searchMap,page,size);

    }

    @PutMapping("state/{id}")
    public Result updateState(@PathVariable Long id){
        return processCompoundService.updateState(id);
    }

}
